package edu.spec.student.controller;

import edu.spec.student.model.Student;
import edu.spec.student.model.mental.Mental;
import edu.spec.student.model.mental.StudentMental;
import edu.spec.student.service.iface.IMentalService;
import edu.spec.student.service.iface.IRubricService;
import edu.spec.student.service.iface.IStudentMentalService;
import edu.spec.student.service.iface.IStudentRubricService;
import edu.spec.basic.model.dto.MvcReturn;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.inject.Inject;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by MadFrog on 2017/6/19.
 */
@Controller
public class MentalController {

    @Inject
    private IRubricService rubricService;
    @Inject
    private IMentalService mentalService;
    @Inject
    private IStudentMentalService studentMentalService;
    @Inject
    private IStudentRubricService studentRubricService;

//    @ResponseBody
//    @RequestMapping("/admin/rubric/listByMental")
//    public MvcReturn listRubricByMental(Integer mentalId){
//        List<Rubric> rList = rubricService.listRubricByMental(mentalId);
//        return new MvcReturn(true, rList);
//    }

    @ResponseBody
    @RequestMapping("/admin/mental/list")
    public MvcReturn list(){
        List<Mental> mList = mentalService.listAll();
        return new MvcReturn(true, mList);
    }



    @ResponseBody
    @RequestMapping("/admin/mental/listAll")
    public MvcReturn listAllMental(){
        return new MvcReturn(true, mentalService.listAll());
    }

    @ResponseBody
    @RequestMapping("/student/mental/listMentalByStudent")
    public MvcReturn listMentalByStudent(HttpSession session){
        Student s = (Student)session.getAttribute("user");
        List<StudentMental> sml = studentMentalService.listStudentMentalByStudent(s.getId());
        return new MvcReturn(true, sml);
    }

    @ResponseBody
    @RequestMapping(value = "/student/mental/finish", method = RequestMethod.POST)
    public MvcReturn finish(@RequestParam(value="rubricId_answer_score[]") String[] rubricId_answer_score, HttpSession session){
        Student s = (Student)session.getAttribute("user");
        Integer mentalId = (Integer)session.getAttribute("mentalId");
        studentRubricService.finish(s.getId(), mentalId, rubricId_answer_score);
        return new MvcReturn(true);
    }

}
